package com.zareal.ymcc.feign;

import com.zareal.ymcc.doc.CourseSearchDoc;
import com.zareal.ymcc.enums.GlobalErrorCode;
import com.zareal.ymcc.result.JSONResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class CourseSearchFeignFallbackFactory implements FallbackFactory<CourseSearchFeign> {
    @Override
    public CourseSearchFeign create(Throwable throwable) {
        throwable.printStackTrace();
        log.error("ES保存数据错误");
        return new CourseSearchFeign() {
            @Override
            public JSONResult saveCourseEs(CourseSearchDoc courseSearchDoc) {
                return JSONResult.error(GlobalErrorCode.COURSE_SEARCH_FUSE.getErrorMessage());
            }

            @Override
            public JSONResult deletCourseEs(Long courseId) {
                return JSONResult.error(GlobalErrorCode.COURSE_SEARCH_FUSE.getErrorMessage());
            }
        };
    }
}
